package single.shop.web.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import single.shop.common.util.BrandDOToBrandVo;
import single.shop.search.model.bean.BrandDO;
import single.shop.web.common.form.QueryForm;
import single.shop.web.service.IndexService;

/**
 * 首页控制器类
 * 
 * @author ladykiller
 * 
 */
@Controller
public class IndexController {
	private static final Log LOG = LogFactory.getLog(IndexController.class);

	@Autowired
	IndexService indexService;

	@Resource
	ThreadPoolTaskExecutor threadPoolTaskExecutor;

	@RequestMapping(value = "/index.do", method = RequestMethod.GET)
	public String index(HttpServletRequest request,
			HttpServletResponse response, QueryForm queryForm, ModelMap modelMap) {

		try {
			indexService.handler(request, modelMap, queryForm);
		} catch (Exception e) {
			LOG.error("出错", e);
			return "error";
		}
		
		return "index";
	}
	
	@RequestMapping(value = "/modify.do", method = RequestMethod.POST)
	public String modify(HttpServletRequest request,
			HttpServletResponse response, QueryForm queryForm, ModelMap modelMap) {

		try {
			BrandDO brandDO = new BrandDO();
			brandDO.setId(queryForm.getId());
			brandDO.setName(queryForm.getName());
			modelMap.put("brand", new BrandDOToBrandVo().handler(brandDO));
		} catch (Exception e) {
			LOG.error("出错", e);
			return "error";
		}
		
		return "ok";
	}

}
